# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution(object):
    def reverseList(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if not head or not head.next:
            return head
        hp = head
        tp = head.next
        while tp.next:
            lp = hp
            hp = tp
            tp = tp.next
            hp.next = lp
        tp.next = hp
        head.next = None
        return tp
